#ifndef FISHEYECALIBRATE_H
#define FISHEYECALIBRATE_H
#include <opencv2/opencv.hpp>
#include <fstream>
#include <string>
using namespace std;
using namespace cv;

class FisheyeCalibrate
{
public:
    FisheyeCalibrate();

public:
    //Step 1: extract corner points in each images
    int extractCornerPoint();
    //Step 2: calibrate camera
    int calibrateCamera();
    //Step 3: evaluate calibration
    int evalCalibration();
    //Step 4: save calibration result
    //Step 4.1: show the calibration result
    int showCalibration();
    //Step 4.2: save calibration result
    int saveCalibration();
    //Step 4.3: load calibration result
    int loadCalibration();
    //Step 5: undistort image with the calibration
    int undistortImage(std::string filename);

private:
    int image_count;
    Size board_size;                    //corner point number
    int success_image_num;				//成功提取角点的棋盘图数量
    vector<Mat>  image_Seq;
    vector<vector<Point2f>>  corners_Seq;   //保存检测到的所有角点/

    vector<vector<Point3f>>  object_Points;        /****  保存定标板上角点的三维坐标   ****/

    vector<int>  point_counts;
    cv::Matx33d intrinsic_matrix;    /*****    摄像机内参数矩阵    ****/
    cv::Vec4d distortion_coeffs;     /* 摄像机的4个畸变系数：k1,k2,k3,k4*/
    std::vector<cv::Vec3d> rotation_vectors;                           /* 每幅图像的旋转向量 */
    std::vector<cv::Vec3d> translation_vectors;                        /* 每幅图像的平移向量 */

    ofstream fout;
    int x_expand, y_expand;		//x,y方向的扩展(x横向，y纵向)，适当增大可以不损失原图像信息

    Mat mapx, mapy, R;
};

#endif // FISHEYECALIBRATE_H
